﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//................
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//.................
namespace QLKTX1._0.DAO
{
    class QuanHeDAO
    {
        public static List<QuanHeDTO> dsQuanHe()
        {
            List<QuanHeDTO> dsQuanHe = new List<QuanHeDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM QuanHe");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                QuanHeDTO qh = new QuanHeDTO();

                qh.MaQuanHe = Int32.Parse(dt.Rows[i]["maQuanHe"].ToString());
                qh.TenQuanHe  = dt.Rows[i]["tenQuanHe"].ToString();


                dsQuanHe.Add(qh );
            }
            return dsQuanHe;
        }
        //ham them 
        public static bool themQuanHe(QuanHeDTO qh)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("INSERT INTO QuanHe(tenQuanHe) VALUES('" + qh.TenQuanHe  + "')");
        }
        //ham xoa 
        public static bool xoaQuanHe(QuanHeDTO qh)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("DELETE FROM QuanHe WHERE maQuanHe='" + qh.MaQuanHe + "' ");
        }
        //ham cap nhat 
        public static bool capNhatQuanHe(QuanHeDTO qh)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("UPDATE QuanHe set tenQuanHe='" + qh.TenQuanHe + "' WHERE maQuanHe='" + qh.MaQuanHe + "' ");
        }
    }


}
